import React from 'react';
import ReactDOM from 'react-dom';
import App from './app';
import {message} from 'antd';
import {registerMicroApps, initGlobalState, MicroAppStateActions,RegistrableApp} from 'qiankun';
import microData from './store/micro-data';

interface MyModule extends NodeModule {
    hot: {
        accept: () => void;
    };
}

const myM: MyModule = module as MyModule;
if (myM && myM.hot) {
    myM.hot.accept();
}

const loader = (loading:boolean)=>{
    console.log(loading)
}


registerMicroApps([
    {
        name: 'my-sub-app',
        entry: 'http://localhost:4004/',
        container: '#my-micro-container',
        //当路由到这里时激活子应用
        activeRule: '#/auth/smartDC',
        loader
    },
],{
    beforeLoad : [(app) => {
        message.info(`开始   加载    子应用  ------  ${app.name}`);
        return Promise.resolve();
    }],
    afterMount: [(app) => {
        message.info(`完毕！！！！   加载    子应用完毕  -----  ${app.name}`);
        microData.updateLoading(false);
        return Promise.resolve();
    }],
    afterUnmount: [(app) => {
        message.info(`子应用已卸载 ------  ${app.name}`);
        return Promise.resolve();
    }],
});


ReactDOM.render(<App />, document.querySelector('#root'));
